import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import {filterRoutes} from './request/authorization'
import routes from './router/router'

const app = createApp(App)


for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
app.use(createPinia())

//获取本地存储中的用户信息中的权限列表
var permissions = JSON.parse( localStorage.getItem('userinfo') ).role.permissions;
//动态过滤用户又权限访问的路由
var accessRoutes = filterRoutes( routes , permissions )
//将过滤出来的路由 动态添加到router中
accessRoutes.forEach((route)=>{
    router.addRoute(route); //循环一次, 添加一条路由
})

app.use(router)

app.mount('#app')
